package cn.ali.controller;

import cn.ali.bean.Student;
import cn.ali.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;


@Controller
@RequestMapping("/student")
public class StudentController {

    public StudentController() {
        System.out.println("StudentController 调用构造函数...");
    }

    @Autowired
    private StudentService studentService;

    @RequestMapping("/find")
    @ResponseBody
    public Student find(long id) {
        Student student = studentService.queryUserById(id);
        return student;
    }

    @RequestMapping("/find2")
    @ResponseBody
    public Student find2(@RequestParam("id") long id) {
        Student student  =new Student();
        return student;
    }

    @RequestMapping("/add")
    @ResponseBody
    public Student add(@RequestBody Student student) {
        return student;
    }


    @RequestMapping("/{studentId}/{studentName}")
    @ResponseBody
    public Student findPath(@PathVariable("studentId") long id, @PathVariable("studentName") String studentName) {
        Student student = studentService.queryUserById(id);
        student.setName(studentName);
        return student;
    }


    @GetMapping("/update")
    @ResponseBody
    public Student update(long id,boolean error) {
        Student student = studentService.queryUserById(id);
        student.setName(UUID.randomUUID().toString());
        studentService.update(student,error);
        return student;
    }


}
